package Junit;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import de.edb.dao.AbstractDataAccessTest;
import de.edb.dao.ArtistDao;
import de.edb.dao.DaoException;
import de.edb.model.Artist;
import de.edb.model.Location;

public class ArtistJunit extends AbstractDataAccessTest{

	private static final int id = 49; // set artist id here for unit test

	private ArtistDao adao;
	
	// Spring will automatically inject the *DAO
	public void setUserService(ArtistDao adao)
	{
	    this.adao = adao;  
	}

	@Test
	public void testCreate() throws DaoException
	{
//		adao.create("JunitTestArtist", "JunitTest", "Test");
//		assertEquals(1, adao.findByName("JunitTestArtist").size());
	}
	
	
	@Test
	public void testDelete() throws DaoException
	{		
//		SessionFactory sessionFactory = this.adao.getSessionFactory();
//		Session session = sessionFactory.getCurrentSession();
//		
//		Artist artist = this.adao.findById(id);			
//		
//		adao.delete(artist);
//		session.flush();
//		assertEquals(0, adao.findByName("JunitTestArtist").size());
	}

	@Test
	public void testFindById()
	{
		Artist artist = this.adao.findById(id);	
		assertTrue(artist.getId()==id);
	}
	
	@Test
	public void testFindAll()
	{
		List<Artist> artist = adao.findAll();
		assertTrue(artist.size() == 5);		
	}
	
	@Test
	public void testFindByName()
	{
		List<Artist> artist = this.adao.findAll(); 
		assertTrue(artist.containsAll(this.adao.findByName("JunitTestArtist")));
		//assertTrue(artist.containsAll(this.adao.findByName("JunitTest")));
	}
	
	public void testSave() throws DaoException
	{
//		Artist artist = this.adao.findById(id);
//		//artist.setCreated(created);
//		artist.setDescription("Junit Test");
//		artist.setGenre("Junit Test");
//		artist.setHomepage("http://www.test.de");	
//		adao.save(artist);
//		assertEquals(1, adao.findByName("JunitTestArtist").size());	
		
	}
	}